-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use the .drectve section for exporting symbols from dlls on Windows #142568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred in compiler/rustc_codegen_ssa |
e63c76b
to
94ec88c
Compare
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
💔 Test failed
|
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
One overall design question: is it supported for folks to run the linker themselves AND specify their own def file? A couple of my changes broke the Chromium and Fuschia folks, so I'm a little paranoid now about changing anything to do with linking that may affect them.
@@ -1116,10 +1122,6 @@ impl<'a> Linker for MsvcLinker<'a> { | |||
// straight to exports. | |||
writeln!(f, "LIBRARY")?; | |||
writeln!(f, "EXPORTS")?; | |||
for symbol in symbols { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that we need the def file any more, we should be able to get away with passing /DLL
to the linker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the mingw docs I read something about the presence of a .DEF file disabling auto-export of certain symbols. I don't know if the same applies to MSVC, so I added it here just to be safe.
This PR on it's own has no effect at all on people running the linker themself. Both the .DEF file and the symbols.o file are only generated when rustc itself runs the linker. As for a future PR that will use weak definitions, those symbols are not meant to be exported from a staticlib anyway. The only case that could break is if someone (Chromium) tries to link rlibs together into a dll and wants to export all symbols, which we don't officially support anyway. The Chromium people have had to adaot their build system for rustc changes anyway and I expect it to not all that hard to adapt to said future weak symbol usage too. |
💔 Test failed
|
The test executable failed with Looks like this is a test for shaking out unused functions: is the compiler supposed to do that, or is it relying on the linker? |
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
8c88ff4
to
fc88eae
Compare
While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.
fc88eae
to
e6aa201
Compare
Squashed everything and reverted some now unnecessary changes. @rustbot ready |
While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.
Necessary for and extracted out of #142366.
Thanks @dpaoliello for figuring out this weird quirk of link.exe!